package com.xujichang.viewbinding.samples

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.xujichang.viewbinding.ViewBindingBase

abstract class ViewBindingFragment<VB : ViewBinding> : Fragment(), ViewBindingBase<VB> {
    val TAG = this::class.simpleName
    private var _binding: VB? = null
    protected val binding: VB get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return createBindingAndReturnView(inflater, container) {
            _binding = it
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}